from abc import ABC
import akshare as ak
from gm.api import *
import numpy as np

from getdata.JuejinConfig import juejin_set_token


class StockTickInterface(ABC):
    def get(self, symbol, start_time, end_time,
            fields='open, close, low, high,volume, bob', frequency='60s'):
        pass


class StockTick_by_Juejin(StockTickInterface):
    def get(self, symbol, start_time, end_time,
            fields='open, close, low, high,volume, bob', frequency='60s'):
        juejin_set_token()
        self.data = history(symbol=symbol, frequency=frequency, start_time=start_time
                            , end_time=end_time,
                            fields=fields, adjust=ADJUST_PREV, df=True)
        return self.data
    def get_all(self, symbol, start_time, end_time,
            fields='open, close, low, high,volume, bob', frequency='60s'):
        juejin_set_token()
        self.data = history(symbol=symbol, frequency=frequency, start_time=start_time
                            , end_time=end_time,
                            fields=fields, adjust=ADJUST_PREV, df=True)
        return self.data


class StockTick_by_Akshare(StockTickInterface):
    def get(self, symbol, start_time, end_time,
            fields='open, close, low, high,volume, bob', frequency='60s'):
        # 'SZSE.002501'
        stock_zh_a_minute_df = ak.stock_zh_a_minute(symbol=symbol, period='1', adjust="qfq")
        # print(stock_zh_a_minute_df)
        return stock_zh_a_minute_df